

//创建class类
class Week1 {
    constructor(){
        this.movies=[{
            title:"The Shawshank Redemption（《肖申克的救赎》",
            id:0
        },{
            title:"The Godfather（《教父》）",
            id:1
        },{
            title:"The Godfather: Part II（《教父 2》）",
            id:2
        },{
            title:"Pulp Fiction（《低俗小说》）",
            id:3
        },{
            title:"The Good, the Bad and the Ugly（《黄金三镖客》）",
            id:4
        },{
            title:"12 Angry Men（《十二怒汉》）",
            id:5
        },{
            title:"Schindler’s List（《辛德勒名单》）",
            id:6
        },{
            title:"The Dark Knight（《黑暗骑士》）",
            id:7
        }];
        this.size=8;
        this.customers=[]
    }
    //显示表里面的元素
    toStrings(){
        return this.movies;
    }

    suijiAdd(title,index){
        for(var i=this.movies.length;i>index;i--){
            this.movies[i]=this.movies[i-1]
        }
        this.movies[index].title=title;
        return this;
    }

    //根据id获取到里面的元素，将之取出来，放到customers里面
    add(name,id){
        this.movies.forEach(item=>{
            if(item.id==id){
                this.customers.push(item)
                for(var i=0;i<this.movies.length;i++){
                    if(this.movies[i].id==id){
                        this.movies.splice(i,1)
                    }
                }
            }
        })
        return this.movies
    }
    //归还，在customers里面删除掉，然后重新放到movies里面
    checkIn(id){
        
        this.customers.forEach((item,index)=>{
            if(item.id==id){
                this.movies.push(item)
                this.customers.splice(index,1)
            }else{
                return -1
            }
        })
        return this.customers
    }
}
let week=new Week1()

console.log(week.add("whj",3))
console.log(week.add("whj",2))
console.log(week.add("whj",4))
console.log(week.checkIn(4))
console.log(week.suijiAdd("是达",5))
console.log(week.toStrings())


// let customers=[]

// Array.prototype.add=function(name,code){

// }

// //显示所有元素
// Array.prototype.toStrings=function(){
//     return this;
// }

// console.log(movies.toStrings())